package news.biz;

import news.dao.UsersDAO;
import news.entity.Users;
import news.utils.MD5Utils;

public class UsersBiz {
	private UsersDAO usersDAO;
	
	/**
	 * 用户验证登录
	 * @param uname
	 * @param upwd
	 * @return
	 */
	public Users userLogin( String uname, String upwd ) {
		Users user = null;
		// 调用数据库方法，处理用户的登录
		user = usersDAO().queryUsersByLogin(uname, MD5Utils.MD5(upwd));
		return user;
	}
	
	/**
	 * 比对老密码
	 * @param pwd
	 * @param uid
	 * @return
	 */
	public Boolean equalsOldPwd( String pwd, int uid ) {
		String oldpwd = usersDAO().queryUsersOldPwd( uid );
		if ( MD5Utils.MD5(pwd).equals(oldpwd) ) {
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * 重置密码
	 * @param pwd
	 * @param uid
	 * @return
	 */
	public boolean resetUserPwd( String pwd , int uid ) {
		boolean flag = false;
		flag = usersDAO().modifyUsersPwdByUserID(MD5Utils.MD5(pwd), uid);
		return flag;
	}
	
	/**
	 * 实例化UsersDAO对象
	 * @return
	 */
	public UsersDAO usersDAO() {
		if(usersDAO == null) {
			usersDAO = new UsersDAO();
		}
		return usersDAO;
	}
}
